package com.xique.door.controller;

import com.xique.common.core.domain.R;
import com.xique.common.core.utils.SecurityUtils;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.door.bean.domain.Notice;
import com.xique.door.service.INoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/notice")
public class NoticeController {

  @Autowired private INoticeService noticeService;

  /** 公告列表 */
  @PreAuthorize(hasPermi = "door:notice:list")
  @GetMapping("/noticeList")
  public R getNoticeList(
      Integer pageNum,
      Integer pageSize,
      String theme,
      String status,
      String startTime,
      String endTime,
      String userName,String exhibitionStatus) {
    Long parkId = SecurityUtils.getParkId();
    pageNum = pageNum != null ? pageNum : 1;
    pageSize = pageSize != null ? pageSize : 10;
    if (parkId != null) {
      return R.ok(
          noticeService.getNoticeList(
              parkId, pageNum, pageSize, theme, status, startTime, endTime, userName,exhibitionStatus));
    } else {
      return R.fail("接口传入的parkId为空");
    }
  }

  /** 添加公告 */
  @PreAuthorize(hasPermi = "door:notice:add")
  @PostMapping("/addNotice")
  public R insertNotice(@RequestBody Notice notice) {
    Long parkId = SecurityUtils.getParkId();
    if (parkId != null) {
      notice.setParkId(parkId);
      return noticeService.insertNotice(notice);
    } else {
      return R.fail("接口传入的parkId为空");
    }
  }

  /** 公告详情 */
  @PreAuthorize(hasPermi = "door:notice:edit")
  @GetMapping("/noticeDetails")
  public R noticeDetails(Long id) {
    Notice notice = noticeService.getNotice(id);
    return R.ok(notice);
  }

  /** 公告修改 */
  @PreAuthorize(hasPermi = "door:notice:edit")
  @PutMapping("/updateNotice")
  public R updateNotice(@RequestBody Notice notice) {
    return noticeService.updateNotice(notice);
  }

  /** 公告状态修改 */
  @PreAuthorize(hasPermi = "door:notice:edit")
  @GetMapping("/updateStatus")
  public R updateStatus(Long id, String status) {

    return noticeService.updateStatus(id, status);
  }
}
